package com.zhuang.blog.base.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.ShearCaptcha;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @Classname ValidateCodeServlet
 * @Description 验证码生成类
 * @Date 2021/10/30 8:19
 * @Author by dell
 */
@RestController
public class ValidateCodeServlet {
    @RequestMapping("/code")
    public String code(HttpSession session){
        // 定义图形验证码的长宽验证码字符数，干扰线宽度
        ShearCaptcha captcha = CaptchaUtil.createShearCaptcha(140, 35, 4, 20);
        // 将正确验证码保存到session中
        String code = captcha.getCode();
        session.setAttribute("code",code);
        return code;
    }
}
